package com.ellricky.market.ui

import android.content.Intent
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ViewUtil
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.adapter.clue.ClueAdapter
import com.ellricky.baselib.entity.clue.MyClueEntity
import com.ellricky.baselib.http.callback.EListCallback
import com.ellricky.baselib.ui.base.BaseRefreshActivity
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.market.API_MARKET_CLUE_LIST
import com.ellricky.market.R
import com.ellricky.market.jumpAddClue

/**
 * 线索簿
 */
class ClueBookActivity : BaseRefreshActivity<Void, BasePresenter<Void>, MyClueEntity>() {

    private var resultCode = 0

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = getString(R.string.market_clue_book)
        mBtnRight.visibility = View.VISIBLE
        ViewUtil.setTextViewDrawable(this, mBtnRight, R.drawable.common_icon_add, 2)
    }

    override fun getResponseCallback(): BaseCallback {
        return object : EListCallback<MyClueEntity>(this) {
            override fun onSuccess(data: MutableList<MyClueEntity>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }

            override fun onErrorCode(code: String?, msg: String?) {
                super.onErrorCode(code, msg)
                rvView.onRefreshFailed(refresh)
            }

            override fun onHttpError(code: String?, msg: String?) {
                super.onHttpError(code, msg)
                rvView.onRefreshFailed(refresh)
            }
        }
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<MyClueEntity>? {
        return null
    }


    override fun getUrlPath(): String {
        return API_MARKET_CLUE_LIST
    }

    override fun onClickBtnRight() {
        super.onClickBtnRight()
        jumpAddClue(this)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        this.resultCode = resultCode
    }

    override fun onKeyBack(isKeyBack: Boolean) {
        if (resultCode > 0){
            setResult(BaseConstant.RESULT_CODE_ADD)
        }
        super.onKeyBack(isKeyBack)

    }

    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, i: Int, l: Long) {
        super.onItemClick(adapterView, view, i, l)
        val entity = adapter[i]
        EAppUtil.jumpPageWithId(this, MarketClueDetailActivity::class.java, entity.id)
    }


}
